package com.zjuee.web.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.dto.common.plan.PlanTreatDto;
import com.zjuee.base.model.common.plan.PlanTreat;
import com.zjuee.service.PlanTreatService;
import com.zjuee.web.ledger.mapper.PlanTreatMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ding jinli
 * @since 1.0
 */
@Slf4j
@Service
public class PlanTreatServiceImpl implements PlanTreatService {
    @Resource
    PlanTreatMapper planTreatMapper;

    @Override
    public Long add(PlanTreat type) {
        int state = planTreatMapper.insert(type);
        if (1 == state) {
            return type.getId();
        }
        return null;
    }

    @Override
    public boolean delete(Long id, Long validateId) {
        PlanTreat planTreat = planTreatMapper.selectById(id);
        if (validateId.equals(planTreat.getWpiId())) {
            int type = planTreatMapper.deleteById(id);
            if (1 == type) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean update(PlanTreat type) {
        int state = planTreatMapper.updateById(type);
        if (1 == state) {
            return true;
        }
        return false;
    }

    @Override
    public PlanTreat selectById(Long id, Long validateId) {
        PlanTreat planTreat = planTreatMapper.selectById(id);
        if (validateId.equals(planTreat.getWpiId())) {
            return planTreat;
        }
        return null;
    }

    @Override
    public Page<PlanTreat> list(PlanTreatDto dto) {
        return null;
    }

    @Override
    public LambdaQueryWrapper<PlanTreat> fuzzyQuery(PlanTreatDto dto) {
        return null;
    }

    @Override
    public List<PlanTreat> getPlanTreat(PlanTreat planTreat) {
        if (planTreat == null) {
            return null;
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        if (planTreat.getWpiId() != null) {
            queryWrapper.eq("wpi_id", planTreat.getWpiId());
        }
        if (planTreat.getWptType() != null) {
            queryWrapper.eq("wpt_type", planTreat.getWptType());
        }
        if (planTreat.getWptBcode() != null) {
            queryWrapper.eq("wpt_bcode", planTreat.getWptBcode());
        }
        if (planTreat.getWptScode() != null) {
            queryWrapper.eq("wpt_scode", planTreat.getWptScode());
        }
        if (planTreat.getWptName() != null) {
            queryWrapper.eq("wpt_name", planTreat.getWptName());
        }
        if (planTreat.getWptDisposeType() != null) {
            queryWrapper.eq("WPT_DISPOSE_TYPE", planTreat.getWptDisposeType());
        }
        if (planTreat.getWptDisposeStype() != null) {
            queryWrapper.eq("WPT_DISPOSE_STYPE", planTreat.getWptDisposeStype());
        }

        return planTreatMapper.selectList(queryWrapper);
    }
}
